package com.example.proxy.dynamic.jdk.demo3;


import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class JdkProxy implements InvocationHandler {


    private Object object;

    public JdkProxy(Object object) {
        super();
        this.object=object;
    }

    public Object getInstance() {
        return Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(),
                this.object.getClass().getInterfaces(),
                this);

    }


    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {

        System.out.println("代理之前的操作");
        Object invoke = method.invoke(this.object, args);
        System.out.println("代理之后的操作");

        return invoke;
    }
}
